# Maintainer: Maxime Gauduin <alucryd@archlinux.org>
# Contributor: Cravix <dr.neemous@gmail.com>
# Contributor: AlexanderR <rvacheva@nxt.ru>
# Contributor: zhn <zhangn1985@gmail.com>

pkgbase=renpy
pkgname=(
  renpy
  renpy-demos
)
pkgver=8.0.3
pkgrel=1
pkgdesc="The Ren'Py Visual Novel Engine"
arch=(loong64 x86_64)
url=https://www.renpy.org
license=(MIT)
depends=(
  ffmpeg
  glew
  python-future
  python-pefile
  python-pygame-sdl2
  python-six
)
makedepends=(
  cython
  git
  python-setuptools
  python-sphinx
  python-sphinx-bootstrap-theme
)
optdepends=(
  'code: Default editor'
)
options=(!emptydirs)
_tag=23e313d5e0376c9a1b13ae6beb7861368f8acc5b
source=(
  git+https://github.com/renpy/renpy.git#tag=${_tag}
  renpy.bin
  renpy.desktop
  renpy.png
  renpy-system-fribidi.patch
  renpy-version.patch
  LICENSE.txt
)
b2sums=('SKIP'
        'bbf0d25ad1671f7046cced56024a9c023533a1c28e9cff62e77203bbecae220d35cbe00a896483324ee3b778a1335c1d156894d6f2b692b4960a5bf48bf5d502'
        'b5bec9d19a25ae849d0e86e483040b320be9048b55ba002cc83d4ee018e99ff7549ba26a60afe6522c2efe2abb724f2679750e25f8d7c161847ad1babeccf006'
        'd0b22e3f970f28096a6ea50019d708a568cfca489acc3c5b1bbce78a0b5afc35d43712b5348ab88b643543ce4f627c31a83eacaab293bede55de2eeabfea2238'
        '1e1c8b1a8d670c7ec1587b13140972d463ba6a442f895e73ba9df45f36c52babe86783180b0d265e4bb93df44ad31ed5c0e9e859d656d253ad086b8fdb784281'
        '12c237ed94d210fee5de799be2c827d38aa994b2727299e1c8a4e8d4e9e60141ff4cc5764ebf070ec3cf50640fe4b851eab95819a401c7880037bc4483815d30'
        '0d5258d59d9bbcd4122b2ffda82b088838b134c250edb0a3e95f727a3bd0c0263d3942d4e27877d192fb14433fce0f8d99aa20e9efcb7df86c884418ba6e1b80')

prepare() {
  cd renpy
  git cherry-pick -n 909e61decbc2d9c63a5c05f0a27a849f4ab205fc
  patch -Np1 -i ../renpy-system-fribidi.patch
  patch -Np1 -i ../renpy-version.patch
}

build() {
  cd renpy
  python module/setup.py build
  python -m compileall renpy
  local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  PYTHONPATH=module/build/lib.linux-x86_64-cpython-${python_version} python renpy.py . compile
  PYTHONPATH=module/build/lib.linux-x86_64-cpython-${python_version} python renpy.py the_question compile
  PYTHONPATH=module/build/lib.linux-x86_64-cpython-${python_version} python renpy.py tutorial compile
  cd sphinx
  PYTHONPATH=../module/build/lib.linux-x86_64-cpython-${python_version} ./build.sh
}

package_renpy() {
  optdepends=(
    'renpy-demos: Tutorial and The Question demos'
    'tk: Set projects directory'
  )

  cd renpy
  python module/setup.py install --root="${pkgdir}" --optimize=1 --skip-build
  install -dm 755 "${pkgdir}"/usr/share/{renpy,doc}
  cp -dr --no-preserve=ownership doc gui launcher renpy renpy.py sdk-fonts "${pkgdir}"/usr/share/renpy/
  ln -s /usr/share/renpy/doc "${pkgdir}"/usr/share/doc/renpy
  install -Dm 755 ../renpy.bin "${pkgdir}"/usr/bin/renpy
  install -Dm 644 ../renpy.desktop -t "${pkgdir}"/usr/share/applications/
  install -Dm 644 ../renpy.png -t "${pkgdir}"/usr/share/pixmaps/
  install -Dm 644 ../LICENSE.txt -t "${pkgdir}"/usr/share/licenses/renpy/
}

package_renpy-demos() {
  depends=(renpy)

  cd renpy
  install -dm 755 "${pkgdir}"/usr/share/renpy
  cp -dr --no-preserve=ownership the_question tutorial "${pkgdir}"/usr/share/renpy/
  install -dm 755 "${pkgdir}"/usr/share/licenses
  ln -s renpy "${pkgdir}"/usr/share/licenses/renpy-demos
}

# vim: ts=2 sw=2 et:
